# data_sources/base_data_source.py
from abc import ABC, abstractmethod
import pandas as pd
from typing import List, Dict
import logging

class BaseDataSource(ABC):
    def __init__(self, source_name: str):
        self.source_name = source_name
        self.logger = logging.getLogger(__name__)

    @abstractmethod
    def get_stock_list(self) -> pd.DataFrame:
        """获取股票列表"""
        pass

    @abstractmethod
    def get_daily_data(self, symbol: str, start_date: str, end_date: str) -> pd.DataFrame:
        """获取日线数据"""
        pass

    # @abstractmethod
    # def get_financial_data(self, symbol: str) -> pd.DataFrame:
    #     """获取财务数据"""
    #     pass

    def normalize_daily_data(self, df: pd.DataFrame) -> pd.DataFrame:
        """标准化日线数据格式"""
        if df.empty:
            return df

        # 标准列名映射
        column_mapping = {
            # 日期列
            'date': 'trade_date', 'Date': 'trade_date', 'datetime': 'trade_date',
            # 价格列
            'open': 'open_price', 'Open': 'open_price',
            'high': 'high_price', 'High': 'high_price',
            'low': 'low_price', 'Low': 'low_price',
            'close': 'close_price', 'Close': 'close_price',
            # 成交量列
            'volume': 'volume', 'Volume': 'volume',
            'amount': 'turnover', '成交额': 'turnover',
            # 其他列
            'change': 'change_rate', 'pct_chg': 'change_rate', '涨跌幅': 'change_rate'
        }

        df = df.rename(columns=column_mapping)
        return df